import algorithm

proc convert*(digits: openArray[int], input, output: int): seq[int] =
  if output < 2 or input < 2:
    raise newException(ValueError, "base should be greater than one")
  var
    current = 0

  for x in digits:
    if x notin {0..input-1}:
      raise newException(ValueError, "invalid digit")
    current = current * input + x

  if current == 0:
    return @[0]

  while current > 0:
    result.add(current mod output)
    current = current div output
  reverse result